<template>
  <router-view v-slot="{ Component }">
    <transition :name="transitionName">
      <keep-alive>
        <div :key="$route.name" class="root-div">
          <component :is="Component" v-if="$route.meta.keepAlive" />
        </div>
      </keep-alive>
    </transition>

    <transition :name="transitionName">
      <div :key="$route.name" class="root-div">
        <component :is="Component" v-if="!$route.meta.keepAlive" />
      </div>
    </transition>
  </router-view>
</template>

<script>
import { computed } from "vue";
import { useRoute } from "vue-router";
import { useStore } from "vuex";
import defaultSetting from "./settings";
export default {
  name: "app",
  setup() {
    const store = useStore();
    const route = useRoute();
    const transitionName = computed(() => {
      let routerUrl = route.path;
      // 添加去除指定页面转场动画
      if (["/", "/pointShopList", "/center"].includes(routerUrl)) {
        return "";
      }
      if (!defaultSetting.needPageTrans) return "";
      return store.state.direction;
    });
    return {
      transitionName,
    };
  },
};
</script>
<style lang="scss">

.root-div {
  position: absolute;
  width: 100%;
}

.slide_left-enter-active,
.slide_left-leave-active,
.slide_right-enter-active,
.slide_right-leave-active {
  transition: all 0.3s;
  position: absolute !important;
  background-color: white;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 1;
}

.slide_left-enter-from,
.slide_right-leave-to {
  opacity: 1;
  transform: translateX(100%);
}

.slide_right-enter-from,
.slide_left-leave-to {
  opacity: 1;
  transform: translateX(-1100%);
}

.slide_left-leave-to,
.slide_right-leave-to {
  opacity: 0.6;
}
</style>
